<template>
  <div style="background: #fff; padding: 24px;">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <a-form-item label="物品名称">
              <a-input placeholder="输入物品名称查询" v-model="queryParam.itemName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域-start -->
    <div class="table-operator" style="margin-bottom: 10px;">
      <a-button type="primary" icon="plus" @click="handleAdd()">新增</a-button>
    </div>
    <!-- 操作按钮区域-end -->
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        <span style="float:right;">
          <a @click="loadData()"><a-icon type="sync" />刷新</a>
        </span>
      </div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定要归还物品吗？" @confirm="() => handleBackWareHouse(record)">
            <a>归还</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <OutWareHouseModal ref="modalForm" @ok="updateList"></OutWareHouseModal>
    <OutWareHouseGoodDetailModal ref="goodDetailForm"></OutWareHouseGoodDetailModal>
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction, postAction } from '@api/manage'
import OutWareHouseModal from './modal/OutWareHouseModal'
import OutWareHouseGoodDetailModal from './modal/OutWareHouseGoodDetailModal'
export default {
  name: 'OutWareHouseList',
  mixins: [JeecgListMixin],
  data() {
    return {
      // 表头
      columns: [
        {
          title: '序号',
          key: 'rowIndex',
          width: 50,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '物品名称',
          align: 'center',
          dataIndex: 'itemName'
        },
        {
          title: '领用人',
          align: 'center',
          dataIndex: 'optUserName'
        },
        // {
        //   title: '工装编号',
        //   align: 'center',
        //   dataIndex: 'optUserName'
        // },
        {
          title: '借记状态',
          align: 'center',
          dataIndex: 'isClosed',
          customRender: (text, record, index) => {
            return text ? '归还' : '借出'
          }
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/outWarehouseCtrl/getOutWarehouseItemList',
        exportXlsUrl: '/inWarehouseCtrl/exportXls'
      }
    }
  },
  components: {
    OutWareHouseModal,
    OutWareHouseGoodDetailModal
  },
  methods: {
    handleBackWareHouse(record) {
      postAction('/outWarehouseCtrl/sendBackOutWarehouseItem', { outItemId: record.id })
        .then(res => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData(this.queryParam)
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.confirmLoading = false
          this.queryParam = {}
          this.selectGoodItem = {}
        })
    },
    handleDetail: function(record) {
      this.$refs.modalForm.title = '详情'
      this.$refs.modalForm.disableSubmit = false
      getAction('/outWarehouseCtrl/getOutWarehouseItemDetail', { outItemId: record.id }).then(res => {
        this.$refs.goodDetailForm.add(res.result)
      })
      // this.defaultMaterialCode = record.materialCode
      // this.$refs.modalForm.edit(record)
      // this.$refs.modalForm.title = '详情'
      // this.$refs.modalForm.disableSubmit = true
    }
  }
}
</script>

<style lang="less" scoped></style>
